<template>
  <div class="icon">
    <div class="search">
      <div><el-input v-model="state.keyword" clearable placeholder="请输入关键字"></el-input></div>
      <div><el-button @click="search">搜索</el-button></div>
    </div>
    <div class="icon-list">
      <div v-for="(x, y) in state.list" :key="y">
        <div :class="'iconfont icon-' + x.font_class"></div>
        <div class="word">{{ x.name }}</div>
        <div class="word">{{ x.font_class }}</div>
        <div class="word">{{ x.unicode }}</div>
        <div class="button" @click="copy(x.font_class)">复制</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { glyphs } from '@/assets/font/iconfont.json'
import { onMounted, reactive } from 'vue';
import element  from '@/utils/element';
const state = reactive({
  keyword: '',
  olds: [],
  list: []
})
onMounted(() => {
  state.list = state.olds = glyphs
})
function search(){
  state.list = state.olds.filter( x=> x.name.includes(state.keyword) || x.font_class.includes(state.keyword)
)
}
function copy(text) {
  navigator.clipboard.writeText(text).then(() => {
    element.success('复制成功')
  })
}
</script>

<style scoped lang="scss">
.search{
  display: flex;
  >div{
    width: 300px;
    margin: 10px;
  }
}
.icon-list {
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  cursor: pointer;
  padding: 20px;

  >div {
    width: 180px;
    height: 180px;
    border: 1px solid #fff;
    padding: 10px;
    margin: 2px;

    .iconfont {
      width: 52px;
      height: 52px;
      border-radius: 10px;
      margin: 3px auto;
      font-size: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .word {
      width: 100%;
      height: 24px;
      display: flex;
      justify-content: center;
      align-items: center;
      word-wrap: break-word;
      font-size: 12px;
      overflow: hidden;
    }

    .button {
      text-align: center;
      cursor: pointer;
    }
  }
  >div:hover{
    background-color: #1889fa;

  }
}
</style>
